
// undeline  to hump
export const formatToHump = function (value) {
  // eslint-disable-next-line no-useless-escape
  return value.replace(/\_(\w)/g, (_, letter) => letter.toUpperCase())
}
// to upppercase uphump
export const formatToUpHump = function (value) {
  // eslint-disable-next-line no-useless-escape
  value = value.replace(/\_(\w)/g, (_, letter) => letter.toUpperCase())
  const arr = value.split('')
  arr[0] = arr[0].toUpperCase()
  return arr.join('')
}

export const toLine = function (name) {
  return name.replace(/([A-Z])/g, '_$1').toLowerCase()
}

export const strTrim = (str) => {
  return str.replace(/(^\s*)|(\s*$)/g, '')
}

// string format
export const strFormat = function () {
  let template = arguments[0]
  for (const key in arguments) {
    if (Number(key) !== 0) {
      const value = arguments[key]
      switch (typeof (value)) {
        case 'number':
        case 'string':
          template = template.replace(/%s/, value)
          break
        case 'object':
          for (const key in value) {
            const str = value[key]
            if (undefined !== str) {
              template = template.replace('{' + key + '}', str)
            }
          }
          break
      }
    }
  }
  return template
}
